package edu.zju.gis.cky.entity.dto;

import edu.zju.gis.cky.cons.Constant;
import edu.zju.gis.cky.entity.Meta;
import edu.zju.gis.cky.util.FileHelper;
import lombok.Data;

import java.util.Date;

@Data
public class InputDTO {

    private String name;

    // land / forest ...
    private String gradation;

    private String depart;

    private String regionNumber;

    private String region;

    private String coordinate;

    private String elevation;

    private String source;

    private Date produceTime;

    private String temporal;

    private String resolution;

    private String sensor;

    private String secret;

    private String description;

    private String other;

    // 文件名（带后缀名）
    private String fileName;

    // 矢量 / 其他
    private String type;

    // 矢量数据表名
    private String tableName;

    // tsv文件字段名称
    // OBJECTID_1,OBJECTID,NAME,SHAPE_LENG,bName,dName,CODE,dCODE,sCODE,cCODE,dispLvIL,dispLvIS,Shape_Le_1,Shape_Le_2,Shape_Area,WKT
    private String fieldNames;

    // tsv文件字段类型
    // int,int,str,str,str,str,str,str,str,str,str,str,double,double,double,str
    private String fieldTypes;

    // shp / gdb文件的图层名
    private String layerName;

    public Meta toMeta() {
        Meta meta = new Meta();
        meta.setName(name);
        meta.setGradation(gradation);
        meta.setDepart(depart);
        meta.setRegionNumber(regionNumber);
        meta.setRegion(region);
        meta.setCoordinate(coordinate);
        meta.setElevation(elevation);
        meta.setSource(source);
        meta.setProduceTime(produceTime);
        meta.setTemporal(temporal);
        meta.setResolution(resolution);
        meta.setSensor(sensor);
        meta.setSecret(secret);
        meta.setDescription(description);
        meta.setOther(other);
        meta.setInputTime(new Date());
        meta.setStorage(Constant.DATA_PATH + "/" + gradation + "/" + fileName);
        meta.setFormat(FileHelper.getSuffix(fileName));
        meta.setSize(FileHelper.getSize(Constant.USER_PATH + "/" + fileName));
        meta.setType(type);
        if (type.equals("矢量")) {
            meta.setPgStorage(tableName);
        }
        meta.setIsTiled("No");
        return meta;
    }

}
